import { Injectable } from '@nestjs/common';
import * as pptxgenjs from 'pptxgenjs';
import * as html2Ppt from 'html-pptxgenjs';
@Injectable()
export class PptExportService {
  async exportToPpt(articles) {
    const pptx = new (pptxgenjs as any)();
    for (const article of articles) {
      const slide = pptx.addSlide();
      const htmlContent = `
        <h1>${article.title}</h1>
        <p><strong>状态</strong>${article.title}</p>
        <p><strong>分类</strong>${article.categories.map((item) => item.name).join(',')}</p>
        <p><strong>标签</strong>${article.tags.map((item) => item.name).join(',')}</p>
        <p>${article.content}</p>
      `;
      const items = html2Ppt.htmlToPptxText(htmlContent);
      slide.addText(items, { x: 0.5, y: 0.5, w: 9.5, h: 6, valign: 'top' });
    }
    return await pptx.write({
      outputType: 'nodebuffer',
    });
  }
}
